<template>
  <!-- 工作组及对应结果 -->
  <div id="wL">
    <Splitpanes>
      <Pane size="65">
        <vxe-toolbar perfect>
          <template #buttons>
            <div class="smallToolTitle">检验主记录</div>
            <div v-if="props.triggerSource==='1'">
              <vxe-button type="text" class="button-blue" content="初步审核" @click="firstReviewMany('1', '初步审核')"></vxe-button>
              <vxe-button type="text" class="button-red" content="取消初审" @click="firstReviewMany('2', '取消初审')"></vxe-button>
              <span class="margin-lr">&nbsp;</span>
              <vxe-button type="text" class="button-blue" content="审核" @click="firstReviewMany('3', '审核')"></vxe-button>
              <vxe-button type="text" class="button-red" content="取消审核" @click="firstReviewMany('4', '取消审核')"></vxe-button>
            </div>
            <div v-if="props.triggerSource==='2'">
              <vxe-button type="text" class="button-blue" @click="handleSearch">查询</vxe-button>
              <vxe-button type="text" class="button-blue" @click="handlePrintMany">打印</vxe-button>
              <!-- <vxe-button status="danger" class="button-blue" icon="vxe-icon-file-txt">工作单</vxe-button> -->
            </div>
          </template>
          <template #tools>
            <span class="text-bold margin0right-xs text-blue">{{`总记录行数:${wL.length}`}}</span>
          </template>
        </vxe-toolbar>
        <div class="tableBody">
          <vxe-table ref="wLTable" class="mytable-scrollbar" border align="left" height="auto" :scroll-y="{ enabled:true }" :loading="showLoading" :data="wL" :cell-style="cellClassName" :row-config="{ isCurrent: true, isHover: true }" :column-config="{ resizable: true }" :keyboard-config="{ isArrow: true }" :sort-config="{ trigger: 'cell' }" @cell-click="wLRowClick" @current-change="wLRowClick" resizable show-overflow>
            <vxe-column type="checkbox" width="26" fixed="left"></vxe-column>
            <vxe-column type="seq" title="#" width="30" fixed="left"></vxe-column>

            <vxe-column field="isUrgent" width="16" align="center" fixed="left" class-name="flag-cell">
              <template #header>
                <span style="font-weight: 150; font-size: 8px">急</span>
              </template>
              <template #default="{ row }">
                <span class="el-icon-first-aid-kit" v-if="row.isUrgent === 1">
                  <el-icon>
                    <WarnTriangleFilled />
                  </el-icon>
                </span>
              </template>
            </vxe-column>
            <vxe-column field="isPrint" width="16" align="center" fixed="left" class-name="flag-cell">
              <template #header>
                <span style="font-weight: 150; font-size: 8px">打</span>
              </template>
              <template #default="{ row }">
                <i class="el-icon-printer" v-if="row.isPrint === 1">
                  <el-icon>
                    <Printer />
                  </el-icon>
                </i>
              </template>
            </vxe-column>
            <vxe-column field="isAutoPrint" width="16" align="center" fixed="left" class-name="flag-cell">
              <template #header>
                <span style="font-weight: 150; font-size: 8px">自</span>
              </template>
              <template #default="{ row }">
                <span class="el-icon-s-platform" v-if="row.isAutoPrint === 1">
                  <el-icon>
                    <Monitor />
                  </el-icon>
                </span>
              </template>
            </vxe-column>
            <vxe-column field="isChk" width="16" align="center" fixed="left" class-name="flag-cell">
              <template #header>
                <span style="font-weight: 150; font-size: 8px">审</span>
              </template>
              <template #default="{ row }">
                <i v-if="row.isChk === 1" class="el-icon-s-check">
                  <span style="color: #fff">初</span>
                </i>
                <i v-else-if="row.isChk === 2 || row.isChk === 1" class="el-icon-finished">
                  <el-icon>
                    <SuccessFilled />
                  </el-icon>
                </i>
              </template>
            </vxe-column>
            <vxe-column field="isAlarm" width="16" align="center" fixed="left" class-name="flag-cell">
              <template #header>
                <span style="font-weight: 150; font-size: 8px">危</span>
              </template>
              <template #default="{ row }">
                <i class="el-icon-warning" v-if="row.isAlarm === 1">
                  <el-icon>
                    <WarningFilled />
                  </el-icon>
                </i>
              </template>
            </vxe-column>
            <vxe-column field="batchActState" title="⚪" width="30" align="center" fixed="left">
              <template #default="{row}">
                <span :class="row.batchActState===true?'vxe-icon-success-circle-fill text-green':row.batchActState===false?'vxe-icon-error-circle-fill text-red':''"></span>
              </template>
            </vxe-column>
            <vxe-column field="batchActMsg" title="失败原因" width="60" align="left" fixed="left">
            </vxe-column>
            <vxe-column field="rptGroupNa" title="报告单元" width="80" sortable>
              <template #default="{ row }">
                <span>{{ row.rptGroupNa }}</span>
              </template>
            </vxe-column>
            <vxe-column field="sampleda" title="检验日期" width="80" sortable>
              <template #default="{ row }">
                <span>{{ row.sampleda }}</span>
              </template>
            </vxe-column>
            <vxe-column field="sampleNo" title="标本号" width="62" sortable>
              <template #default="{ row }">
                <span>{{ row.sampleNo }}</span>
              </template>
            </vxe-column>
            <!-- <vxe-column field="sampleNo" title="审核状态" width="75" sortable>
              <template #default="{ row }">
                <span v-if="row.isChk === null || row.isChk === 0">未审核</span>
                <span v-else-if="row.isChk === 1">初审</span>
                <span v-else-if="row.isChk === 2">审核</span>
              </template>
            </vxe-column> -->
            <vxe-column field="reqNo" title="条码号" width="90" sortable>
              <template #default="{ row }">
                <span>{{ row.reqNo }}</span>
              </template>
            </vxe-column>
            <vxe-column field="patNa" title="姓名" width="70" sortable>
              <template #default="{ row }">
                <span>{{ row.patNa }}</span>
              </template>
            </vxe-column>
            <vxe-column field="patNo" title="病历号" width="128">
              <template #default="{ row }">
                <span>{{ row.patNo }}</span>
              </template>
            </vxe-column>
            <vxe-column field="patTypeNa" title="类型" width="50" sortable></vxe-column>
            <vxe-column field="reqDeptNa" title="科室" width="70" show-overflow></vxe-column>
            <vxe-column field="sex" title="性别" width="35" show-overflow>
              <template #default="{ row }">
                {{ getSexName(row) }}
              </template>
            </vxe-column>
            <vxe-column field="age" title="年龄" width="50" show-overflow></vxe-column>
            <vxe-column field="testPurpose" title="检验目的" width="170" show-overflow></vxe-column>
            <vxe-column field="bedNo" title="床号" width="60" show-overflow></vxe-column>
            <vxe-column field="sampleTypeNa" title="样本类型" min-width="100" show-overflow></vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane size="35">
        <vxe-toolbar perfect>
          <template #buttons>
            <div class="smallToolTitle inspeResultsTitle">检验结果</div>
          </template>
        </vxe-toolbar>
        <div class="tableRight">
          <vxe-table ref="wLResultTable" border align="left" resizable show-overflow height="auto" v-loading="loading" :data="wLResultList" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{ isArrow: true }" :cell-style="calcCellBgColor">
            <vxe-column type="seq" title="#" width="30" fixed="left"></vxe-column>
            <vxe-column field="itemNo" title="检验项目" min-width="120">
              <template #default="{ row }">
                {{ `${row.itemNo} ${row.itemNa}` }}
              </template>
            </vxe-column>
            <vxe-column field="testResult" title="结果" width="80"></vxe-column>
            <vxe-column field="resultFlag" title="" width="40">
              <template #default="{ row }">
                <span class="padding-lr-xs text-df">{{ getResultFlag(row.resultFlag) }}</span>
                <span class="padding-lr-xs" v-if="row.isAlarm === '1' || row.isAlarm === 1">{{ row.alarmText }}</span>
              </template>
            </vxe-column>
            <vxe-column field="ref" title="参考范围" width="80"></vxe-column>
          </vxe-table>
        </div>
      </Pane>
    </Splitpanes>
    <!-- 静默打印 -->
    <QuietPrint ref="quietPrintRef" :printParams="printParamsObj" />
    <!-- 审核密码授权 -->
    <ChkAuthComp ref="ChkAuthCompRef" />
  </div>
</template>
<script setup lang="ts">
// 引入组件区 ==========
import {reactive, ref, defineExpose, getCurrentInstance, onMounted, onUnmounted, watch} from 'vue';
import { VXETable } from 'vxe-table';
import { IsEmpty, formatDateTime, sortByField } from '@/utils/common.ts';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { Splitpanes, Pane } from 'splitpanes';
import { getOptionValueByCodeRptGroupOption, getOptionValueByCodeGlobalOption } from '@/utils/SysOptionsHelper';
import { mainInfoSort } from '@/views/lab_sys/lab_bus/components/TestListUtils';
import { ElLoading } from 'element-plus';
import QuietPrint from '@/components/QuietPrint.vue';
import ChkAuthComp from '@/components/ChkAuthComp.vue';
import {isEmpty} from "lodash";
import { AppStore } from '@/stores/store';

//#region  属性
let props = defineProps({
  triggerSource: { type: String, default: '1' } /**1：批量审核，2：批量打印 */
});
//#endregion

// 全局变量定义区 ==========
const storeObj = AppStore();
let { proxy }: any = getCurrentInstance();
let wL: any[] = reactive([]); //病人列表数据
let wLResultList: any[] = reactive([]); //项目列表数据
let patTypeList: any[] = reactive([]); //字典表：病人类型
let sexList: any[] = reactive([]); //字典表：性别
let form: any = reactive({});
let wLTable = ref(null);
let currentWkltRow: any = reactive({});
let loading = ref(false); //刷新+表格加载
let printParamsObj = ref(null);
let patTypeCodes = reactive([]); //病人类型所需code集合
let reqDeptCodes = reactive([]);
let reqWardCodes = reactive([]);
let testDoctorCodes = reactive([]);
let showLoading = ref(false);
let testChkDoctorObj = reactive({ testDoctor: '', testDoctorNa: '', chkDoctor: '', chkDoctorNa: '' });
let ChkAuthCompRef = ref(null); //审核授权弹窗对象

//#region  监听属性
watch(() => storeObj.chkDoctorObj, (n, o) => {
  if (!IsEmpty(n.code)) {
    testChkDoctorObj.chkDoctor = n.code;
  }
  if (!IsEmpty(n.name)) {
    testChkDoctorObj.chkDoctorNa = n.name;
  }
}, { deep: true, immediate: true });

defineExpose({
  getWklt
});

// 方法定义区 =============
// 页面加载时字典
onMounted(() => {
  wL.length = 0;
  wLResultList.length = 0;
  getDictDetailList(); //加载病人类型字典
  getDictSexList(); //加载性别字典
});

onUnmounted(() => {
  wL.length = 0;
  wLResultList.length = 0;
});

// 获取工作列表
function getWklt(formWklt) {
  showLoading.value = true;
  wL.length = 0; //放入数据前清空数据
  wLResultList.length = 0;
  Object.assign(form, formWklt);
  // 病人类型
  patTypeCodes.length = 0;
  form.visitTypes.forEach((item) => {
    patTypeCodes.push(item.code);
  });
  //科室
  reqDeptCodes.length = 0;
  form.deps.forEach((item) => {
    reqDeptCodes.push(item.code);
  });
  //病区
  reqWardCodes.length = 0;
  if (form.reqWards) {
    form.reqWards.forEach((item) => {
      reqWardCodes.push(item.code);
    });
  }

  //检验医师
  testDoctorCodes.length = 0;
  form.registrants.forEach((item) => {
    testDoctorCodes.push(item.username);
  });

  const url = '/lab/maininfo/findReviewedResutByLabMaininfo';
  const data = {
    wtId: form.wtId,
    orgId: form.orgId,
    rptGroup: form.wtId,
    scheduleDateBegin: IsEmpty(form.scheduleDateBegin) ? '' : formatDateTime(form.scheduleDateBegin, 'yyyy-MM-dd') + ' 00:00:00',
    scheduleDateEnd: IsEmpty(form.scheduleDateEnd) ? '' : formatDateTime(form.scheduleDateEnd, 'yyyy-MM-dd') + ' 23:59:59',
    visitTypeIds: patTypeCodes,
    specTypeIds: form.specTypeIds,
    reqDepts: reqDeptCodes, //科室(code)
    reqWards: reqWardCodes, //病区(code)
    testDoctor: testDoctorCodes, //检验医师(username)
    sampleNo: form.sampleNo,
    isReviewed: form.isReviewed, //是否审核
    isPrinted: form.isPrinted, //是否打印
    isFilterNoResult: form.isFilterNoResult, //根据结果筛选
    isFilterNoSpecCode: form.isFilterNoSpecCode, //根据条码号筛选
    isFilterNoPatName: form.isFilterNoPatName, //根据病人姓名筛选
    customSorting: form.customSorting, //打印顺序
    reqWard: form.reqWard
  };
  proxy.$http
    .post(url, data)
    .then((res: any) => {
      wL.length = 0;
      proxy.$nextTick(() => {
        wL.push(...res.data);
        wLRowClick({ row: wL[0] });
      });
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage(err, VxeNotifyType.error);
    });
}
// 行点击事件
function wLRowClick({ row }: any) {
  if (IsEmpty(row)) {
    wLResultList.length = 0;
    return;
  }
  Object.assign(currentWkltRow, row);
  if (wLTable.value) {
    wLTable.value?.setCurrentRow(row);
    wLTable.value?.focus();
  }
  getWkltResultList();
}
//从词典获取所有的病人类型
// 获取界面字段
function getDictDetailList() {
  patTypeList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'PATTYPE' } })
    .then((res: any) => {
      patTypeList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
function getPatTypeName(row) {
  // proxy.$nextTick(() => {
  if (patTypeList.length > 0 && row.patType !== null) {
    const group = patTypeList.find((item) => item.code == row.patType);
    return group.name;
  }
}
//获取性别数据字典
function getDictSexList() {
  sexList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'SEX' } })
    .then((res: any) => {
      sexList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
function getSexName(row) {
  // proxy.$nextTick(() => {
  if (sexList.length > 0 && !IsEmpty(row.sex)) {
    const group = sexList.find((item) => item.code == row.sex);
    if (isEmpty(group) || isEmpty(group.name)) {
      return '';
    }
    return group.name;
  }
}


// 初步审核
async function firstReviewMany(chkStatus, str) {
  let arr = [];
  //2、缓存中，检验医师、审核医师没有过期 则使用缓存中的数据
  if (storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.code)) {
    const curDateTime = new Date().valueOf();
    if (Number(curDateTime) > Number(storeObj.chkDoctorObj.expressin)) {
      if (ChkAuthCompRef.value) {
        ChkAuthCompRef.value?.initPage(true, '审核');
      }
      return;
    }
  } else {
    if (ChkAuthCompRef.value) {
      ChkAuthCompRef.value?.initPage(true, '审核');
    }
    return;
  }
  const wLTable = proxy.$refs.wLTable;
  if (wLTable) {
    arr = wLTable.getCheckboxRecords(true);
  }
  if (!(arr && arr.length > 0 && arr[0])) {
    VxeMessage('请勾选要审批的数据', VxeNotifyType.info);
    return;
  } else {
    let data = {
      chkValue: 1,
      labMaininfos: arr
    };
    let url = '';
    /**初审 */
    let actionStr = '';
    if (chkStatus === '1') {
      url = '/lab/maininfo/batchChkLabMaininfo';//'/lab/maininfo/bachChkBatchChk';
      data.chkValue = 1;
      data.chkDoctor= storeObj && storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.code) ? storeObj.chkDoctorObj.code : '';
      data.chkDoctorNa = storeObj && storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.name) ? storeObj.chkDoctorObj.name : '';
      actionStr = '批量初审';
    }
    /**取消初审 */
    if (chkStatus === '2') {
      //Todo
      actionStr = '取消初审';
    }
    /**审核 */
    if (chkStatus === '3') {
      url = '/lab/maininfo/batchChkLabMaininfo';//'/lab/maininfo/bachChkBatchChk';
      data.chkValue = 2;
      data.caType = window.apiUrl.CA_TYPE;
      data.chkDoctor= storeObj && storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.code) ? storeObj.chkDoctorObj.code : '';
      data.chkDoctorNa = storeObj && storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.name) ? storeObj.chkDoctorObj.name : '';
      actionStr = '批量审核';
    }
    /**取消审核 */
    if (chkStatus === '4') {
      //Todo
      actionStr = '取消审核';
    }

    const type = await VXETable.modal.confirm(`确定要${actionStr}选中的${arr.length}条数据?`); /*不能改el  $confirm 回车事件冒泡你*/
    if (type !== 'confirm') {
      return;
    }
    const loadingInstance = ElLoading.service({ lock: true, text: '请稍后...', background: 'rgba(0,0,0,0)' });
    if (chkStatus === '11111') {
      proxy.$http
        .post(url, data)
        .then((res: any) => {
          if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1) {
            getWklt(form);
            VxeMessage('批量操作成功', VxeNotifyType.success);
          }
          if (res && res.status && !IsEmpty(res.status.code) && (res.status.code === 400 || res.status.code === 0)) {
            VxeMessage(res.status.msg, VxeNotifyType.error);
          }
          loadingInstance.close();
        })
        .catch((err: any) => {
          loadingInstance.close();
          VxeMessage('批量操作失败,请联系管理员', VxeNotifyType.error);
        });
    }
    if (chkStatus === '1' || chkStatus === '3') {
      arr.forEach((op, idx) => {
        data.labMaininfos = [];
        data.labMaininfos.push(op);
        proxy.$http
          .post(url, data)
          .then((res: any) => {
            if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data && res.data.length > 0) {
              wL.forEach((mm, ii) => {
                if (mm.id === res.data[0].id) {
                  mm.batchActState = res.data[0].batchActState;
                  mm.batchActMsg = res.data[0].batchActMsg;
                  Object.assign(mm, res.data[0]);
                }
              });
            }
            if (idx === arr.length - 1) {
              loadingInstance.close();
            }
          })
          .catch((err: any) => {
            VxeMessage('批量操作失败,请联系管理员', VxeNotifyType.error);
          });

      });
    }
    if (chkStatus === '2' || chkStatus === '4') {
      let params = {
        labMaininfoList: arr,
        unchkState: chkStatus === '2' ? 1 : chkStatus === '4' ? 2 : 2,
        rptGroup: form.wtId,
        sampleNo: form.sampleNo
      };
      proxy.$http
        .post('/lab/maininfo/unChkMainInfoMany', params)
        .then((res: any) => {
          if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1) {
            getWklt(form);
            VxeMessage('批量操作成功', VxeNotifyType.success);
          }
          if (res && res.status && !IsEmpty(res.status.code) && (res.status.code === 400 || res.status.code === 0)) {
            VxeMessage(res.status.msg, VxeNotifyType.error);
          }
          loadingInstance.close();
        })
        .catch((err: any) => {
          loadingInstance.close();
          VxeMessage('批量操作失败,请联系管理员', VxeNotifyType.error);
        });
    }
  }
}
// 获取检验结果
function getWkltResultList() {
  wLResultList.length = 0;
  loading.value = false;
  const url = '/lab/maininfo/findRptResultByLabMaininfo';
  const data = {
    id: currentWkltRow.id
  };
  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      wLResultList.length = 0;
      //wLResultList.push(...res.data);
      wLResultList.push(...sortByField(res.data, 'displayOrder', 'asc'));
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}
function getResultFlag(val) {
  const a = getOptionValueByCodeRptGroupOption('zjmaccsxs');
  if (a === '1' || a === 1) {
    if (val === 'H') {
      const b = getOptionValueByCodeRptGroupOption('pgjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↑';
    }
    if (val === 'L') {
      const b = getOptionValueByCodeRptGroupOption('pdjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↓';
    }
    if (val === 'P') {
      const b = getOptionValueByCodeRptGroupOption('yxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '+';
    }
    if (val === 'Q') {
      const b = getOptionValueByCodeRptGroupOption('ryxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '±';
    }
    if (val === 'M') {
      const b = getOptionValueByCodeRptGroupOption('zcjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '';
    }
    if (val === 'E') {
      const b = getOptionValueByCodeRptGroupOption('cwjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '×';
    }
    if (val === 'N') {
      const b = getOptionValueByCodeRptGroupOption('nxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '√';
    }
  }
  if (val === 'H') {
    return '↑';
  }
  if (val === 'L') {
    return '↓';
  }
  if (val === 'P') {
    return '+';
  }
  if (val === 'Q') {
    return '±';
  }
  if (val === 'N') {
    return '√';
  }
  if (val === 'E') {
    return '×';
  }
  if (val === 'M') {
    return '';
  }
  return '';
}
/**
 * 单元格背景颜色
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【2】偏高结果颜色  hresultcolor
 *【3】偏低结果颜色  lresultcolor
 *【4】阳性结果颜色  presultcolor
 *【5】正常结果颜色  mresultcolor
 *【6】弱阳性结果颜包  qresultcolor
 *【7】错误结果颜色  errresultcolor
 *【8】阴性结果颜色  nresultcolor
 *【9】结果标志颜色显示方式 jgbzysxsfs (0:背景色  1:文字颜色)
 */
function calcCellBgColor({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  /**偏高【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'resultFlag') {
    //查询系统选项偏高显示颜色   背景色还是文字颜色
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#ff0000' };
  }
  /**偏高【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#ff0000', color: '#fff' };
  }

  /**偏低【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**偏低【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**弱阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ee' };
  }
  /**弱阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ee', color: '#fff' };
  }

  /**错误【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#800000' };
  }
  /**错误【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#800000', color: '#fff' };
  }

  /**正常【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**正常【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**阴性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**阴性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**危急值 颜色 */
  if (row && !IsEmpty(row.isAlarm) && row.isAlarm === 1 && column && column.field === 'itemNo') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    const b = getOptionValueByCodeGlobalOption('isalarmcolor');
    const d = getOptionValueByCodeGlobalOption('wjzyssfxswbjys'); /**危急值颜色显示是否为背景颜色 wjzyssfxswbjys */
    if (a === 1 || a === '1') {
      if (!IsEmpty(b)) {
        if (d && (d === '1' || d === 1)) {
          return { background: b, color: '#fff' };
        } else {
          return { color: b };
        }
      }
    }
  }
}

/**单元格样式
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【1】急背景色  isurgentcolor
 *【2】打背景色  isprintcolor
 *【3】自助机打印背景色  isautoprintcolor
 *【4】审核背景色  ischkcolor
 *【5】危急值背景色  isalarmcolor
 *【6】门诊类型病人列表颜色  mzpattypecolor
 *【7】住院类型病人列表颜色  zypattypecolor
 *【8】急诊类型病人列表颜色  jzpattypecolor
 *【9】体检类型病人列表颜色  tjpattypecolor
 *【10】其他类型病人列表颜色  qtpattypecolor
 */
function cellClassName({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  let patTypeColor = '';
  if (column && !IsEmpty(column.fixed)) {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      if (row && row.patType === '1') {
        //门诊
        const b = getOptionValueByCodeGlobalOption('mzpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '2') {
        //急诊
        const b = getOptionValueByCodeGlobalOption('jzpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '3') {
        //住院
        const b = getOptionValueByCodeGlobalOption('zypattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '4') {
        //体检
        const b = getOptionValueByCodeGlobalOption('tjpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else {
        //其他
        if (!IsEmpty(row.patType)) {
          const b = getOptionValueByCodeGlobalOption('qtpattypecolor');
          if (!IsEmpty(b)) {
            patTypeColor = b;
          }
        }
      }
    }
  }
  if (column.property === 'isUrgent') {
    if (row.isUrgent === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isurgentcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff', padding: '0', margin: '0' };
        }
      }
      return { background: '#FF0000', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isChk') {
    if (row.isChk === 2) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#008000', color: '#fff' };
    } else if (row.isChk === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#00FF00', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAlarm') {
    if (row.isAlarm === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isalarmcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#FF9900', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAutoPrint') {
    if (row.isAutoPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isautoprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#800080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isPrint') {
    if (row.isPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#000080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
}
/**查询检验主记录 */
function handleSearch() {
  proxy.$emit('search');
}
/**批量打印操作 */
async function handlePrintMany() {
  let arr = [];
  const wLTable = proxy.$refs.wLTable;
  if (wLTable) {
    arr = wLTable.getCheckboxRecords(true);
  }
  if (!(arr && arr.length > 0 && arr[0])) {
    VxeMessage('请勾选要打印的数据', VxeNotifyType.info);
    return;
  } else {
    let data = { labMaininfos: arr };
    let url = '/lab/maininfo/bachChkBatchPrint';
    const type = await VXETable.modal.confirm(`确定要批次打印选中的${arr.length}条数据?`); /*不能改el  $confirm 回车事件冒泡你*/
    if (type !== 'confirm') {
      return;
    }
    const loadingInstance = ElLoading.service({ lock: true, text: '请稍后...', background: 'rgba(0,0,0,0)' });
    proxy.$http
      .post(url, data)
      .then((res: any) => {
        if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1) {
          getWklt(form);
          VxeMessage('批量操作成功', VxeNotifyType.success);
          if (res.data && res.data.labRptmainList && res.data.labRptmainList.length > 0) {
            if (res.data.labRptmainList && res.data.labRptmainList.length > 0) {
              let arr = [];
              for (let e of res.data.labRptmainList) {
                arr.push({ ReportName: e.rptTemplateCode, ReportParameters: [{ Name: 'Id', Value: e.id }], PdfPrinterSetting: { PdfPrinterCopies: 1 } });
              }
              printParamsObj.value = arr; //[{ ReportName: '1759924571139497986', ReportParameters: [{ Name: 'Id', Value: '123' }], PdfPrinterSetting: { PdfPrinterCopies: 1 } }]; // { id: new Date().valueOf(), params: ['123', '345', '567'] };
            }
          }
        }
        if (res && res.status && !IsEmpty(res.status.code) && (res.status.code === 400 || res.status.code === 0)) {
          VxeMessage(res.status.msg, VxeNotifyType.error);
        }
        loadingInstance.close();
      })
      .catch((err: any) => {
        loadingInstance.close();
        VxeMessage('批量操作失败,请联系管理员', VxeNotifyType.error);
      });
  }
}
</script>
<style lang="scss" scoped>
#wL {
  height: 100%;
  // 附加按钮间距
  .button-blue,
  .button-red {
    margin: 5px 0 5px 5px;
  }
  .tableBody {
    height: calc(100% - 40px);
  }
  .inspeResultsTitle {
    height: 34px;
    line-height: 34px;
  }
  .tableRight {
    height: calc(100% - 40px);
  }
}
:deep(.flag-cell) {
  .vxe-cell {
    padding: 0 2px !important;
  }
}
</style>
